class Field < ActiveRecord::Base
  has_and_belongs_to_many :trackers
  has_many :entries
  
  validates_uniqueness_of :name

  def get_entry!(ticket)
    ets = Entry.find(:all,
      :conditions => [ "ticket_id = ? AND field_id = ?", ticket.id, self.id ] )
    #et = self.entries.find(:ticket => ticket)
    if ets.length == 0
      et = new_entry
      et.field = self
      ticket.entries << et
      et
    else
      ets.first
    end
  end
end
